package org.sidora.strata.site;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import org.openide.util.NbBundle;
import org.openide.util.Utilities;
import org.openide.windows.TopComponent;
import org.sidora.core.Phase;


/**
 * Action which shows PhaseForm component.
 * @author Enric Tartera, Juan Manuel Gimeno, Roger Masgoret
 * @version 1.0
 */
public class PhaseFormAction extends AbstractAction {
    
    public PhaseFormAction() {
        super(NbBundle.getMessage(PhaseFormAction.class, "CTL_PhaseFormAction"));
//        putValue(SMALL_ICON, new ImageIcon(Utilities.loadImage(PhaseFormTopComponent.ICON_PATH, true)));
    }
    
    public void actionPerformed(ActionEvent evt) {
        TopComponent win = PhaseFormTopComponent.findInstance();
        win.open();
        win.requestActive();
    }
    
    public void actionPerformed(Phase phase) {
        PhaseFormTopComponent pftc;
        pftc = (PhaseFormTopComponent)PhaseFormTopComponent.findInstance();
        pftc.saveAllData();
        pftc.setPhase(phase);
        pftc.fillSiteFields();
        pftc.open();
        pftc.requestActive();
    }
    
    public void clearFields(){
        PhaseFormTopComponent pftc;
        pftc = (PhaseFormTopComponent)PhaseFormTopComponent.findInstance();
        pftc.emptySiteFields();
    }
    
    public void close() {
        PhaseFormTopComponent win = PhaseFormTopComponent.findInstance();
        win.saveAllData();
        win.close();
    }
}
